package org.ihelpuoo.weboo.action.http.session;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import org.ihelpuoo.util.Pager;
import org.ihelpuoo.weboo.Weboo;
import org.ihelpuoo.weboo.action.http.AjaxListAction;
import org.ihelpuoo.weboo.bean.LocaleObject;
import org.ihelpuoo.weboo.module.ActionContext;

public class GetAvaliableLocalesAction extends AjaxListAction
{
	@Override
	protected List generateList(ActionContext context, Pager pager) throws Exception
	{
		List<Locale> avas = context.getAvaiableLocales();
		Iterator<Locale> it = avas.iterator();
		List<LocaleObject> list = new ArrayList(avas.size());
		while (it.hasNext())
		{
			Locale l = it.next();
			String v = (null == l ? Weboo.DEFAULT_LOCALE_NAME : l.toString());
			LocaleObject lo = new LocaleObject();
			lo.setValue(v);
			lo.setText(context.getMessage("locale." + v));
			list.add(lo);
		}
		return list;
	}

}
